#include "headfiles.h"

using namespace std;

static unsigned int calcNs(unsigned int num, unsigned int N) {
    unsigned int num_of_Ns = 0;
    unsigned int remaining, result;
    result = num / N;
    remaining = num % N;
    while (remaining == 0) {
        ++num_of_Ns;
        num = result;
        result = num / N;
        remaining = num % N;
    }

    return num_of_Ns;
}

unsigned calcTrailingZeros(int n) {
    if (n < 1) {
        return 0;
    }

    unsigned int i;
    unsigned int num_of_5s, num_of_2s;
    num_of_2s = 0;
    num_of_5s = 0;
    for (i = 2; i <= n; i++) {
        num_of_2s += calcNs(i, 2);
        num_of_5s += calcNs(i, 5);
    }

    return (num_of_2s > num_of_5s) ? num_of_5s : num_of_2s;
}


